package com.youdoneed.community.media.service;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.youdoneed.base.application.AppException;
import com.youdoneed.community.common.utils.StringUUIdUtil;
import com.youdoneed.community.media.dao.ForummediaresourceMapper;
import com.youdoneed.community.media.entity.Forummediaresource;

@Service
public class ForummediaresourceService {
	private final Logger logger = LoggerFactory.getLogger(ForummediaresourceService.class);
	
	@Autowired
	ForummediaresourceMapper forummediaresourceMapper;
	
	/**
	 * 保存媒体资源
	 * @param forummessage
	 * @return int
	 * @author lid
	 * @date 2017.6.28
	 */
	@Transactional
	public int saveForumMediaResource(Forummediaresource forummediaresource) {
		if(null == forummediaresource){
			throw new AppException("forummediaresource参数不允许为空");
		}
		
		try {
			forummediaresource.setMediaResourceId(StringUUIdUtil.getUUID());
			forummediaresource.setCreateDate(new Date());
			
			return forummediaresourceMapper.insert(forummediaresource);
		} catch (Exception e) {
			logger.info("保存媒体资源失败"+e);
			return 0;
		}
	}
}
